{% extends 'form_div_layout.html.twig' %}
{# Adapts form type views to bootstrap.
 # Templates are taken from Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig 
 #}
{% block form_row %}
{% spaceless %}
    {# wraps forms into a div.form-group element. #}
    <div class="form-group{% if errors|length > 0 %} has-error{% endif %}">
        {{ form_errors(form) }}
        {{ form_label(form) }}
        {{ form_widget(form) }}
    </div>
{% endspaceless %}
{% endblock form_row %}

{% block form_start %}
{% spaceless %}
    {# set the role attribute of the form to 'form' #}
    {% set attr = attr|merge({'role': 'form', 'class': 'row form-horizontal'}) %}
    {% set method = method|upper %}
    {% if method in ["GET", "POST"] %}
        {% set form_method = method %}
    {% else %}
        {% set form_method = "POST" %}
    {% endif %}
    <form name="{{ form.vars.name }}" method="{{ form_method|lower }}" action="{{ action }}"{% for attrname, attrvalue in attr %} {{ attrname }}="{{ attrvalue }}"{% endfor %}{% if multipart %} enctype="multipart/form-data"{% endif %}>
    {% if form_method != method %}
        <input type="hidden" name="_method" value="{{ method }}" />
    {% endif %}
{% endspaceless %}
{% endblock form_start %}

{% block form_widget_simple %}
{% spaceless %}
    {# Add form-control as default class prefix #}
    {% set attr = attr|merge({'class': 'form-control ' ~ attr.class|default('')|trim}) %}
    {% set type = type|default('text') %}
    {# to form-horizontal to have correct alignment #}
    <div class="{{ wrapper_class|default('col-sm-10') }}">
        <input type="{{ type }}" {{ block('widget_attributes') }} {% if value is not empty %}value="{{ value }}" {% endif %}/>
    </div>
{% endspaceless %}
{% endblock form_widget_simple %}

{% block button_widget %}
{% set attr = attr|merge({'class': 'btn ' ~ attr.class|default('btn-primary ')}) %}
{% spaceless %}
    {% if label is empty %}
        {% set label = name|humanize %}
    {% endif %}
    {# add selector class if needed #}
    {% if is_datatables_selector is defined and is_datatables_selector %}
        {% set attr = attr|merge({'class': 'bxtr-autoload-datatables-selector ' ~ attr.class|default }) %}
    {% endif %}
    <button type="{{ type|default('button') }}" {{ block('button_attributes') }}>
        {# optionally add an icon to a button (with icon_button form type) #}
        {% if icon_class is defined %}
            <span class="glyphicon glyphicon-{{ icon_class }}"></span>
        {% endif %}
        {{ label|trans({}, translation_domain) }}
    </button>
{% endspaceless %}
{% endblock button_widget %}

{% block form_label %}
{% spaceless %}
    {% if label is not sameas(false) %}
        {% if not compound %}
            {% set label_attr = label_attr|merge({'for': id}) %}
        {% endif %}
        {% set label_attr = label_attr|merge({'class': (label_attr.class|default('col-sm-2') ~ ' control-label')|trim}) %}
        {% if required %}
            {% set label_attr = label_attr|merge({'class': (label_attr.class|default('') ~ ' required')|trim}) %}
        {% endif %}
        {% if label is empty %}
            {% set label = name|humanize %}
        {% endif %}
        <label{% for attrname, attrvalue in label_attr %} {{ attrname }}="{{ attrvalue }}"{% endfor %}>{{ label|trans({}, translation_domain) }}</label>
    {% endif %}
{% endspaceless %}
{% endblock form_label %}

{% block form_errors %}
{% spaceless %}
    {% if errors|length > 0 %}
    {#<ul>#}
        {% for error in errors %}
            {#<li>{{ error.message }}</li>#}
            <p class="col-sm-12 bg-danger">{{ error.message }}</p>
        {% endfor %}
    {#</ul>#}
    {% endif %}
{% endspaceless %}
{% endblock form_errors %}

{% block choice_widget %}
    <div class="{{ wrapper_class|default('col-md-10') }}">
        {% set attr = attr|merge({class: attr.class|default('form-control')}) %}
        {{ parent() }}
    </div>
{% endblock choice_widget %}
{% block date_widget %}
{% spaceless %}
    {% if widget == 'single_text' %}
        {{ block('form_widget_simple') }}
    {% else %}
        <div {{ block('widget_container_attributes') }}>
            {{ date_pattern|replace({
                '{{ year }}':  form_widget(form.year, { wrapper_class: 'col-sm-1'} ),
                '{{ month }}': form_widget(form.month, { wrapper_class: 'col-sm-1'} ),
                '{{ day }}':   form_widget(form.day, { wrapper_class: 'col-sm-1'} ),
            })|raw }}
        </div>
    {% endif %}
{% endspaceless %}
{% endblock date_widget %}
